package com.ctshk.rpc.hotel.mapper;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

import java.util.List;

public class HotelProductIncreaseStrategyProvider {
    public String selectIdListByHotelProductIds(List<Long> hotelProductIds) {
        return new SQL() {{
            SELECT("select aeis.id ");
            FROM("t_hotel_product_strategy aeis");
            if (CollectionUtils.isNotEmpty(hotelProductIds)) {
                StringBuilder whereStr = new StringBuilder();
                whereStr.append("aeis.hotel_product_id in (");
                for (int i = 0; i < hotelProductIds.size(); i++) {
                    whereStr.append("#{list.get(0)}");
                    if (i == hotelProductIds.size() - 1) {
                        whereStr.append(")");
                    } else {
                        whereStr.append(",");
                    }
                }
                WHERE(whereStr.toString());
            }
        }}.toString();
    }

    public String selectByHotelProductIdNowDate(@Param("hotelProductId") Long hotelProductId, @Param("nowDate") String nowDate) {
        return new SQL() {{
            SELECT("aeis.id, aeis.increase_strategy_name, aeis.self_sale_permission_type, aeis.agent_sale_permission_type, aeis.hotel_product_id, aeis.self_sale_permission_id, aeis.agent_sale_permission_id ");
            FROM("t_hotel_product_strategy aeis ");
            LEFT_OUTER_JOIN("t_hotel_product_strategy_date aeisd ON (aeis.id=aeisd.increase_strategy_id)");
            WHERE("aeis.hotel_product_id = #{hotelProductId}");
            WHERE("#{nowDate} between aeisd.date_begin AND aeisd.date_end");
        }}.toString();
    }
}
